﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data;
using System.Data.SqlClient;
namespace UcAsp.Net.ModelCreate
{
    public partial class Main : DevExpress.XtraEditors.XtraForm
    {
        public Main()
        {
            InitializeComponent();
        }
        public void IntoDatabaseName(string name)
        {
            if (ServerName.Text != string.Empty && LoginName.Text != string.Empty && LoginPasswords.Text != string.Empty)
            {
                if (DatabaseName.Properties.Items.Count < 1)
                {
                    try
                    {
                        DataBase database = new DataBase("Data Source=" + ServerName.Text + ";Initial Catalog=master;User ID=" + LoginName.Text + ";Password=" + LoginPasswords.Text + ";MultipleActiveResultSets=True");
                        SqlDataReader rd = database.ExecuteReader(TableSql.DatabaseSql);
                        while (rd.Read())
                        {
                            DatabaseName.Properties.Items.Add(rd.GetString(0));
                        }
                    }
                    catch
                    {
                        if (name == "DatabaseName")
                        {
                            MessageBox.Show("用户或密码错误");
                        }
                    }
                }
            }
        }

        private void comboBoxEdit1_Properties_Click(object sender, EventArgs e)
        {
            TextEdit TextName=sender as TextEdit;
            IntoDatabaseName(TextName.Name);
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            new Models().CreateModel(ServerName.Text, LoginName.Text, LoginPasswords.Text, DatabaseName.Text, ClassNames.Text, Entities.Text);
        }
    }
}